<template>
    <div class="DecRoot" style="padding-top:0;">
        <el-button
              type="primary"
              icon="el-icon-plus"
              @click="dialogVisible = true"
              plain
              style="margin-bottom: 20px"
              >新增</el-button
            >
            <el-table
              :data="tableData"
              style="width: 100%"
              height="62vh"
              header-cell-class-name="tableHeader"
              stripe
            >
              <el-table-column label="序号" type="index" width="50">
              </el-table-column>
              <el-table-column prop="name" label="频道名"> </el-table-column>
  
              <el-table-column prop="address" label="操作" width="100">
                <template slot-scope="scope">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="编辑"
                    placement="top"
                  >
                    <img
                      @click="edit(scope.row)"
                      src="@/assets/image/icon/edit.png"
                      class="iconImg"
                      alt=""
                    />
                  </el-tooltip>
                  <el-popconfirm
                    title="确定要删除该条频道吗？"
                    @confirm="deleteContent(scope.row)"
                  >
                    <template slot="reference">
                      <i
                        class="el-icon-delete"
                        style="font-size: 25px; color: #409eff; cursor: pointer"
                      ></i>
                    </template>
                  </el-popconfirm>
                </template>
              </el-table-column>
            </el-table>
      <el-dialog :visible.sync="dialogVisible" width="30%" class="newDialog">
        <div class="DiaLogHeader">
          <div class="titlebOX">
            {{ form.id ? "编辑频道" : "新增频道" }}
          </div>
          <div class="chahao" @click="dialogVisible = false">
            <i class="el-icon-close"></i>
          </div>
        </div>
        <el-divider></el-divider>
        <div style="padding: 10px">
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="频道名：">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="btnBox">
          <el-button type="primary" @click="save"> 确定</el-button>
          <el-button @click="dialogVisible = false"> 取消</el-button>
        </div>
      </el-dialog>
    
    </div>
  </template>
    
    <script>
  import {
    selectMarketLocation,
    saveMarketLocation,
    deleteMarketLocation,
    updateMarketLocation
    
  } from "@/api/DataManagement";
  export default {
    name: "aboutUs",
    data() {
      return {
        tableData: [],
        dialogVisible: false,
        form: {},
        tzForm:{}
      };
    },
    created() {
        this.selectMarketLocation()
    },
    methods: {
    //删除市场
    deleteContent(row) {
      deleteMarketLocation({
        idList: row.id,
        nameKeyWord:'SizeGroup'
      }).then((data) => {
        if (data.code == 200) {
          this.$message.success("操作成功");
          this.selectMarketLocation();
        }
      });
    },
    save() {
      let params = {};
      if (!this.form.id) {
        params = {
          name: this.form.name,
          nameKeyWord:'SizeGroup'
        };
        saveMarketLocation(params).then((data) => {
          if (data.code == 200) {
            this.$message.success("操作成功");
            this.dialogVisible = false;
            this.selectMarketLocation();
          }
        });
      } else {
        params = {
          id: this.form.id,
          name: this.form.name,
          nameKeyWord:'SizeGroup'
        };
        updateMarketLocation(params).then((data) => {
          if (data.code == 200) {
            this.$message.success("操作成功");
            this.dialogVisible = false;
            this.selectMarketLocation();
          }
        });
      }
     
    },
    edit(row) {
      this.form = JSON.parse(JSON.stringify(row));
      this.dialogVisible = true;
    },
    //获取所在市场
    selectMarketLocation() {
      selectMarketLocation(
        {
          nameKeyWord:'SizeGroup'
        }
      ).then((data) => {
        this.tableData = data.data;
      });
    },
    },
    watch: {
      dialogVisible() {
        if (!this.dialogVisible) {
          this.form = {};
        }
      },
    },
  };
  </script>
    
          <style scoped lang="scss">
  /deep/ .el-card__body {
    min-height: 80vh;
  }
  .btnBox {
    display: flex;
    justify-content: center;
    background: #fff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 10px 0;
  
    .btnImg {
      width: 14px;
      height: 14px;
      vertical-align: middle;
    }
  }
  
  .DecRoot {
    padding: 20px;
    padding-left: 5px;
    padding-bottom: 0;
    padding-top: 0;
  
    .newCard {
      height: 75vh;
      margin-top: 20px;
    }
  
    /deep/ .el-button {
      padding: 9px 15px;
    }
  
    .el-card {
      .headerBox {
        display: flex;
        justify-content: space-between;
        align-items: center;
  
        .leftBox {
          display: flex;
          align-items: center;
          font-size: 18px;
          font-weight: 700;
  
          /deep/ .el-form-item {
            margin-bottom: 0;
          }
  
          /deep/ .el-input--suffix {
            width: 200px;
          }
        }
      }
  
      /deep/ .tableHeader {
        background: #edf3ff;
        font-weight: 700;
        color: #666666;
      }
  
      .iconImg {
        width: 20px;
        height: 20px;
        cursor: pointer;
        margin-right: 10px;
      }
  
      .pagination {
        display: flex;
        justify-content: space-between;
        margin-top: 10px;
  
        /deep/ .el-pagination__editor.el-input .el-input__inner {
          height: 28px !important;
        }
  
        /deep/ .el-input--mini .el-input__inner {
          height: 28px !important;
        }
      }
    }
  }
  </style>
        <style scoped lang="scss">
  .titlebOXSA {
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
  }
  .newDialog {
    /deep/ .el-divider {
      margin: 0px;
    }
    /deep/ .el-dialog__header {
      padding: 0;
    }
    /deep/ .el-form-item__content {
      width: 75%;
    }
    /deep/ .el-select {
      width: 100%;
    }
    /deep/ .tableHeader {
      background: #edf3ff;
      font-weight: 700;
      color: #666666;
      padding: 5px 0;
    }
    .btnBox {
      display: flex;
      justify-content: center;
      background: #fff;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 10px 0;
      .btnImg {
        width: 14px;
        height: 14px;
        vertical-align: middle;
      }
      /deep/ .el-button {
        padding: 10px 20px;
      }
    }
    .DiaLogHeader {
      display: flex;
      padding: 10px 20px;
      justify-content: space-between;
      .titlebOX {
        font-size: 16px;
        font-weight: 700;
      }
      .chahao {
        width: 20px;
        height: 20px;
        background-image: url("@/assets/image/icon/chahao.png");
        background-size: 100% 100%;
        text-align: center;
        line-height: 20px;
        color: #e65f00;
        cursor: pointer;
      }
    }
    /deep/ .el-input {
      width: 100% !important;
    }
  }
  /deep/ .el-dialog__header {
    font-weight: 700;
  }
  /deep/ .demo-ruleForm {
    padding: 10px;
  }
  
  /deep/ .el-form-item {
    margin-bottom: 8px;
  }
  /deep/ .el-form-item__error {
    z-index: 99;
  }
  /deep/ .el-dialog__body {
    padding: 0;
    padding-top: 10px;
    padding-bottom: 60px;
  }
  .dialogTextBox {
    font-size: 14px;
    color: #000000;
  }
  </style>
    